import java.util.Comparator;
import java.util.PriorityQueue;

class Student implements Comparable<Student>{
    public int age;
    public String name;

    public Student(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    public int compareTo(Student o) {
        return this.age - o.age;
    }
}
class comparatorName implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);//比较的是字符串，需要调用compareTO
    }
}
class comparatorAge implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}
public class Test {
    public static void main(String[] args) {
        Student student1 = new Student(10,"zhangsan");
        Student student2 = new Student(12,"lisi");
        comparatorName comName = new comparatorName();
        PriorityQueue<Student> priorityQueue = new PriorityQueue<>(comName);
        priorityQueue.offer(student1);
        priorityQueue.offer(student2);

    }
    public static void main2(String[] args) {
        Student student1 = new Student(10,"zhangsan");
        Student student2 = new Student(12,"lisi");
        PriorityQueue<Student> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(student2);
        priorityQueue.offer(student1);
    }

    public static void main1(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(10);
        priorityQueue.offer(9);
        priorityQueue.offer(8);
        priorityQueue.offer(7);
        priorityQueue.offer(6);
        priorityQueue.poll();
        priorityQueue.poll();
    }

}
